package com.qf.controller;

import com.qf.pojo.Route;
import com.qf.service.RouteService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：冯国清
 * 项目名：com.qf.controller
 * 时间：2020/7/29 21:19
 * 描述:
 */
@Controller
public class RouteController {
    @Resource
    private RouteService couteService;
    @RequestMapping("/coute")
    @ResponseBody
    public Map<String,Object> getAllCoute(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "5")int limit){
        Map<String, Object> map  = null;
        List<Object> list = new ArrayList<>();
        List<Route> allCoute= couteService.getAllCoute(page,limit);
/* //主键
    private int rid;
    //路由名称标示
    private String rgatewayApiName;
    //服务接口地址
    private String rinsideApiUrl;
    //服务名称
    private String rserviceld;
    //介绍消息
    private String rdescription;
    //状态
    private int rstate;
    //幂等性
    private int ridempotents;
    //是否收费
    private int rneedfee;*/
        for (Route c : allCoute) {
            map = new HashMap<>();
            map.put("rid", c.getRid());
            map.put("rgatewayApiName", c.getRgatewayApiName());
            map.put("rinsideApiUrl", c.getRinsideApiUrl());
            map.put("rserviceld", c.getRserviceld());
            map.put("rdescription",c.getRdescription());
            if (1 == c.getRstate()) {
                map.put("rstate", "正常");
            } else {
                map.put("rstate", "停用");
            }
            if (1 == c.getRidempotents()) {
                map.put("ridempotents", "幂等性");
            } else {
                map.put("ridempotents", "非幂等性");
            }
            if (1 == c.getRneedfee()) {
                map.put("rneedfee", "收费");
            } else {
                map.put("rneedfee", "不收费");
            }
            list.add(map);
        }
        Map<String, Object> CouteMap = new HashMap<>();
        CouteMap.put("code", 0);
        CouteMap.put("msg", "");
        CouteMap.put("count", couteService.getCount());
        CouteMap.put("data", list);
        return CouteMap;
    }
//    @ResponseBody
//    @RequestMapping("/addAppliction")
//    public String saveApplication(Application application){
//        int i = applicationService.saveApplication(application);
//        if (i>=1){
//            return "success";
//        }else {
//            return "failed";
//        }
//    }
//    @RequestMapping("/selectApplicationById1/{aid}")
//    public String selectApplicationById1(@PathVariable int aid, Model model){
//        Application application = applicationService.selectApplicationById(aid);
//        model.addAttribute("application",application);
//
//        System.out.println(1111);
//        System.out.println(application);
//        System.out.println(1111);
//
//        return "/ShowApplication1.jsp";
//    }
//    @RequestMapping("/selectApplicationById2/{aid}")
//    public String selectApplicationById2(@PathVariable int aid,Model model){
//        Application application = applicationService.selectApplicationById(aid);
//        System.out.println(application);
//        model.addAttribute("application",application);
//        return "/UpdateApplication.jsp";
//    }
//    @RequestMapping("/selectById/{aid}")
//    public Application selectCustomerById(@PathVariable int aid,Model model){
//        Application application = applicationService.selectApplicationById(aid);
//        return application;
//    }
//    @ResponseBody
//    @RequestMapping("/updateApplication")
//    public String updateApplication(Application application){
//        int i = applicationService.updateApplication(application);
//        if (i>=1){
//            return "success";
//        }else {
//            return "failed";
//        }
//    }
//    @RequestMapping("/deleteApplication/{aid}")
//    @ResponseBody
//    public String deleteApplication(@PathVariable int aid){
//        System.out.println(aid);
//        int i = applicationService.deleteApplication(aid);
//        if (i>=1){
//            return "success";
//        }
//        return "failed";
//    }
//    @RequestMapping("/deleteApplication1")
//    @ResponseBody
//    public AjaxMessage delete(@RequestParam("aids")int[] aids){
//
//        if(aids!=null&&aids.length>0){
//           applicationService.deleteByIds(aids);
//            return new AjaxMessage(true,"删除成功");
//        }
//        return new AjaxMessage(false,"删除失败");
//    }

}


